package me.tonywang.quartz;

import me.tonywang.common.util.SystemUtils;
import org.quartz.SchedulerException;
import org.quartz.simpl.HostnameInstanceIdGenerator;
import org.quartz.spi.InstanceIdGenerator;

/**
 * @className: IpInstanceIdGenerator
 * @description:
 * @author: WANGHUI
 * @createDate: 2018/5/17 15:40
 * @version: 1.0
 */
public class IpPidInstanceIdGenerator implements InstanceIdGenerator {

    @Override
    public String generateInstanceId() throws SchedulerException {
        String ip =  SystemUtils.getInetAddress() ;
        String pid = SystemUtils.getPid();
        if(ip!=null && pid !=null)
            return SystemUtils.getInetAddress()+"@"+SystemUtils.getPid();
        else
            return new HostnameInstanceIdGenerator().generateInstanceId();
    }
}
